#include "PCH.h"
#include "D3D11RenderDevice.h"
using namespace DeviousRenderer;

D3D11RenderDevice::D3D11RenderDevice()
{

}

D3D11RenderDevice::~D3D11RenderDevice()
{
}

DeTexture2DPtr D3D11RenderDevice::CreateTexture2D(int sizeX, int sizeY, EPixelFormat format, uint numMips, dword flags)
{
	ID3D11Texture2D*	pTexture = NULL;
	D3D11_TEXTURE2D_DESC desc;
	desc.Width = sizeX;
	desc.Height = sizeY;
	desc.MipLevels = numMips;
	desc.Format = GD3D11Format[format];
	desc.Usage = GetD3D11Usage(flags);
	desc.BindFlags = GetD3D11BindFlag(flags);
	HRESULT hr = m_pDevice->CreateTexture2D(&desc, NULL, &pTexture);
	DeTexture2DPtr pDeTexture2DPtr = new DeD3D11Texture2D(pTexture);
	return pDeTexture2DPtr;
}

DeRenderTargetViewPtr D3D11RenderDevice::CreateRenderTargetView(const DeTexture2DPtr& texture2D)
{
	ID3D11RenderTargetView* pRTV = NULL;
	HRESULT hr = m_pDevice->CreateRenderTargetView(texture2D->GetResource(), NULL, &pRTV);
	DeRenderTargetViewPtr pDeRenderTargetView = new DeD3D11RenderTargetView(pRTV);
	return pDeRenderTargetView;
}

D3D11_USAGE D3D11RenderDevice::GetD3D11Usage(dword flags)
{
	if (flags & (PBF_RENDER_TRAGET | PBF_DEPTH_STENCIL))
	{
		return D3D11_USAGE_DEFAULT;
	}
	else
	{
		//TODO
	}
}

D3D11_BIND_FLAG D3D11RenderDevice::GetD3D11BindFlag(dword flags)
{
	dword D3D11Flags = 0;
	if (flags & PBF_RENDER_TRAGET)
	{
		D3D11Flags |= D3D11_BIND_RENDER_TARGET;
	}
	if (flags & PBF_DEPTH_STENCIL)
	{
		D3D11Flags |= D3D11_BIND_DEPTH_STENCIL;
	}
	//TODO

	return D3D11Flags;
}